package leetcode;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * ClassName: BaiduT1
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/2 19:19
 * @Version 1.0
 */
public class HuaweiT3 {

    private static int n;
    private static int r;
    private static long k;
    private static int[] cities;
//    private static int[] bestPlace;
    private static long[] initialQuality;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        r = scanner.nextInt();
        k = scanner.nextLong();
        n = scanner.nextInt();

        if (n <= 0) {
            System.out.println(0);
            scanner.close();
            return;
        }

        cities = new int[n];
        long totalInitialServices = 0;
        for (int i = 0; i < n; i++) {
            cities[i] = scanner.nextInt();
            totalInitialServices += cities[i];
        }
        scanner.close();

        preprocessBestPlacements();

        long low = 0, high = totalInitialServices + k, ans = 0;

        while (low <= high) {
            long mid = low + (high - low) / 2;
            if (check(mid)) {
                ans = mid;
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        System.out.println(ans);

    }

    private static void preprocessBestPlacements() {
        initialQuality = new long[n];
        long currentWindowsSum = 0;

        int start = Math.max(0, 0 - r);
        int end = Math.min(n-1, 0+r);

        for (int i = start; i <= end; i++) {
            currentWindowsSum += cities[i];
        }

        for (int i = 0; i < n; i++) {

            initialQuality[i] = currentWindowsSum;

            int leftRemove = i - r;
            if (leftRemove >= 0) {
                currentWindowsSum -= cities[leftRemove];
            }

            int rightAdd = i + r + 1;
            if (rightAdd < n) {
                currentWindowsSum += cities[rightAdd];
            }
        }
    }

    private static boolean check(long targetQuality) {
        long serversAdded = 0;
        long[] diff = new long[n+1];
        long currentAddedQuality = 0;

        for (int i = 0; i < n; i++) {

            currentAddedQuality += diff[i];
            long currentTotalQuality = initialQuality[i] + currentAddedQuality;

            if (currentTotalQuality < targetQuality) {
                long deficit = targetQuality - currentTotalQuality;
                serversAdded += deficit;

                if (serversAdded > k) {
                    return false;
                }

                currentAddedQuality += deficit;

                int placementCity = Math.min(i + r, n - 1);
                int endidx = placementCity + r + 1;

                if (endidx < n) {
                    diff[endidx] -= deficit;
                }

            }

        }
        return true;

    }
}
